package com.esd.db.tool;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayFundTransToaccountTransferRequest;
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;
import com.esd.db.model.AlipayInfo;

public class AlipayUtils {

	private static String url="https://openapi.alipay.com/gateway.do";
	private static String pid="2017031306195532";
	
	private static String  private_key="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCACoaKBdw2IX+pTqg9crscgF/TCZvlGILCmPaCNPNqz7vkbQKU4D9ZePVV5J+eRPnO2EXJ6m0lRWzSY2bwEb/gQDYcqHyinTYeZF4+vjFryyodN3s6mNGelM8GttSyZChWazahXBkCbAHQRzZ768AEaIUbeYMuc2RwiIl7z4njeFVCGWOYD8jWDPZT6vOHGCW2O+lGxnIZb+omkFduqv75hCUW+WNu6sIXUPqHVkmdN/WEYOPF2kfVdCbmlWqb2SE6QOPf+xqO6hOsgALhI2jotaDYp49b4dBv88+VVnbSrdN+PQ/XY0QccO/YyEYyLYpcWM14W2rg1iwvFK78DgWnAgMBAAECggEATf8baaScOlU5oPcLQTNMi9YfiTzHPE0sCkKHl1WOGjik6kcFVY8sx+IJAOOd4BmAWuIf0Rn+lr+txJNMt1z4lzBGRjrUgXJm7yiQyIOvM0y1QMr1RAKnXoSjgCGLe4fLkqkIxE6H5ZPJnwhiRiab95N70fq5UGh2fJ6PsV4BTxCrLJnnfyxGRnA65dRyBLgiKvujb4jyez3EMATv99I0ESWbUUFFRr/w2vpvEXvtdtUR+WchmlMfrrv7i19eljagCu8XNz1qOkebWV0GB2KyKLBkeuJaaGA0gjMgJTAiSeJ0wfIvdz4ToEn1gmySvfvue3FBHYWsdW+iNORdLzKScQKBgQD9UKfIvL1c4gxQdDRFXQWdWIOxXYRQNKZAzRB4P3fRB2ArBn10/mVBMzGwoQpJO+zUbs38wK3w3EuAHG6ecZP6non4VVRjg/KZZSt9lSHxRhvT38kF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k92W0uESDQerc9qa2F3qWC1yYDvbFrdhoPVv7KHWPfAKkbGmOnd81Ch9glqUindjQVlfCnTa5ljcwIDAQAB";
	
	
	
//	public static void main(String[] args) {
//		AlipayInfo a = new AlipayInfo();
//		a.setAlipayId("12314212314123");
//		a.setOutBizNo("12314212314123");
//		a.setPayeeAccount("13206662783");
//		a.setAmount(0.1);
//		a.setPayeeRealName("孙博");
//		a.setWorkerId(123312);
//		try {
//			a = fundTransfer(a);
//		} catch (AlipayApiException e) {
//			e.printStackTrace();
//		}
//		System.out.println(a.toString());
//	}
	
	public static AlipayInfo fundTransfer(AlipayInfo alipayInfo) throws AlipayApiException {
		String payerRealName = "哈尔滨中科亿信科技开发有限公司";
		String biz="{" 
				+ "\"out_biz_no\":\""+alipayInfo.getOutBizNo()+"\"," 
				+ "\"payee_type\":\"ALIPAY_LOGONID\","
				+ "\"payee_account\":\""+alipayInfo.getPayeeAccount()+"\"," 
				+ "\"amount\":\""+alipayInfo.getAmount()+"\","
				+ "\"payer_real_name\":\""+payerRealName+"\"," 
				+ "\"payer_show_name\":\"语音标注费\","
				+ "\"payee_real_name\":\""+alipayInfo.getPayeeRealName()+"\"," 
				+ "\"remark\":\"语音标注费\","
				+ "\"ext_param\":\"{\\\"order_title\\\":\\\"标注平台查询编码:"+alipayInfo.getOutBizNo()+"\\\"}\"" 
				+ "}";
		AlipayClient alipayClient = new DefaultAlipayClient(url, pid,
				private_key, "json", "UTF-8", alipay_public_key, "RSA2");
		AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();
		request.setBizContent(biz);
		AlipayFundTransToaccountTransferResponse response = alipayClient.execute(request);
		alipayInfo.setAlipayReturnCode(response.getCode());                  
		alipayInfo.setAlipayReturnMsg(response.getMsg());
		alipayInfo.setOrderId(response.getOrderId());
		alipayInfo.setPayerRealName(payerRealName);
		alipayInfo.setPayDate(response.getPayDate());
		alipayInfo.setSubCode(response.getSubCode());
		alipayInfo.setSubMsg(response.getSubMsg());
		alipayInfo.setIsSuccess(response.isSuccess());
		return alipayInfo;		
	}
	
	
}
